/**
 * 3
 *  
 * @Author : roryrywang
 * @DateTime : 24-9-4 下午6:54
 */

#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

struct node {
    int x;
    int y;
    int level;

    node() {}

    node(int x, int y, int level) {
        this->x = x;
        this->y = y;
        this->level = level;
    }
};

bool cmp(node a, node b) {
    return a.level < b.level;
}

int main() {
    int n, k, x, y;
    cin >> n >> k >> x >> y;

    vector<node> vec;
    vec.push_back({x, y, 0});

    for (int i = 0; i < n; ++i) {
        int a, b, c;
        cin >> a >> b >> c;
        vec.push_back({a, b, c});
    }

    sort(vec.begin(), vec.end(), cmp);

    double f[n + 1][k + 1][2];

    for (int i = 0; i <= n; ++i) {
        for (int j = 0; j <= k; ++j) {
            if (i == 0) {
                f[i][j][0] = 0;
            }
            f[i][j][0] = f[i - 1][k][1] + sqrt((vec[i].x - vec[0].x) * (vec[i].x - vec[0].x) +
                                               (vec[i].y - vec[0].y) * (vec[i].y - vec[0].y));
//            if (j>0) f[i][j][0] = min(f[i][j][0],f[i-1][])
        }
    }


    return 0;
}